/*
 * @lc app=leetcode.cn id=46 lang=cpp
 *
 * [46] 全排列
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
// @lc code=start
class Solution {
public:
    vector<vector<int>> ret;
    vector<int> tmp;
    
    void dfs(vector<int>& nums,vector<int>& used) {
        if(tmp.size() == nums.size()) {
            ret.push_back(tmp);
            return ;
        }
        for(int i = 0;i < nums.size();i++) {
            if(used[i] == 1) {
                continue;
            }
            tmp.push_back(nums[i]);
            used[i] = 1;
            dfs(nums,used);
            used[i] = 0;
            tmp.pop_back();
        }
    }
    vector<vector<int>> permute(vector<int>& nums) {
        vector<int> used(nums.size(),0);
        dfs(nums,used);
        return ret;
    }
};
// @lc code=end

